package com.ruoyi.factory.taxShare.controller;

import com.ruoyi.common.utils.StringUtils;
import nccloud.open.api.auto.token.cur.utils.APICurUtils;
import nccloud.open.api.auto.token.itf.IAPIUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.Set;

/**
 * @ClassName Testopnapi
 * @Description: TODO
 * @Author LiuJiaji
 * @Date 2024/4/1 16:56
 **/
public class Testopnapi {


    public static void main(String[] args) throws Exception {
        IAPIUtils util = null;
        //		util = new APIOldUtils(); // 2021.05之前版本
        util = new APICurUtils();// 2021.05版本及以后版本
        // 服务地址ip
        String ip = "192.168.0.152";
//        String ip = "192.168.0.111";
//        String ip = "192.168.0.249";
        // 服务端口号
        String port = "3010";
//        String port = "10010";
//        String port = "8188";
        // 账套编码，开发环境使用develop，生产环境需要使用用root账号登录，在“系统管理”节点查看账套编码
        String busi_center = "01";
        // 第三方应用编码
        String app_id = "cs";
        // app_secret，用于请求加签
        String app_secret = "69979e0f9328404e892f";
        // 公钥，加解密使用
        String public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq03Xmmw33vS9hIABdYooYqanwj9eCZTIrqp87UFG9XjB2kjNuR/xba8s08QgB3et4W43cB3oTyY+t9Y/C43d5eBizEIWGTOSBkFCtm1qoakjhUW7Fwiak4dlOY1B0e2OPLtfep1Axx0BGga/LfbDEjL4Jrrl/nhX9aDx7Q0E8Lx4EZUvO+FchOqDJ9d/yv65dh5XaCgKRrteMyQb9R11ByV3NyJkD9p30107OsJtMThubhTv27yEDx2Cr+9jVuwnp5meVqLSrfgioaTYIUyWqaPTOIuCrIrSRC/aDKCLEOGf15WWW8MrVk1dXCu97vmzpwnruro6V2MuqCMyzN9p9QIDAQAB";
        // ncc用户名
        String ncc_user = "001194";
        // ncc用户密码
        String password = "admin123!@#";
//        String secret_level = "L0";
        String grant_type = "client";
        util.init(ip, port, busi_center, app_id, app_secret, public_key, ncc_user, password);
        util.setGrant_type(grant_type);
        // 获取token
        String token = util.getToken();
        System.out.println("获取token"+token);
        // 请求的OpenAPI接口地址，注意nccloud前面没有"/ nccloud/api/nccloud/api/uapbd/psndocmanage/psndoc/add"
//        String apiuri = "nccloud/api/pu/invoice/save";
        String apiuri = "nccloud/api/riaorg/orgmanage/org/queryOrgByOrgtype2";
//        String apiuri = "nccloud/api/uapbd/customermanage/baseinfo/getCustomerbaseinfo";
//        String apiuri = "nccloud/api/pu/invoicemanage/baseinfo/setInvoicebaseinfo";
//        String apiuri = "nccloud/api/platform/attachmentuploadurl/baseinfo/uploadfileurl";
//        String apiuri = "nccloud/api/pu/invoice/save";
        util.setApiUrl(apiuri);

        String requestParam = "{\n" +
                "\"orgtype2\":\"Y\",\n" +
                "\"version\":\"2\"\n" +
                "}";
        System.out.println("参数"+requestParam);
        // 携带token访问接口，获取结果
        String result = util.getAPIRetrun(token, requestParam);
        System.out.println("返回结果"+result);
    }
}
